< previous page page_745 next page >

Page 745
Launching an Internet Shortcut
There are a couple of ways to launch an Internet shortcut from Visual Basic. You can use an API call or shell out to another program, which opens the browser for you.
The Windows API call ShellExecute executes the program associated with the .URL extension. If everything has been set up properly, the associated program should be your default browser. As with all API calls, you first have to declare them.
sarrow.gifSee "Using API Calls in Visual Basic," p. 452
The following code segment launches the site using the ShellExecute API and the file C:\TEMP.URL:
Const SW_SHOWNORMAL = 1
Dim lRetVal As Long 'RETURN VALUE
Dim lWindow As Long 'BROWSER HWND
lRetVal = ShellExecute(lWindow, "open", "C:\Temp.URL", "", "", SW_SHOWNORMAL)
note.gifShellExecute and FindExecutable are API calls that can be used to determine which program is associated with a certain file extension and then launch the program. They are not limited to use with Internet shortcuts, which is why many of the parameters in the example are left blank. square.gif

Using the ShellExecute API to launch a Web site is easy, but there is even an easier method. Windows has a program called RUNDLL32.EXE, which is used to call functions in a DLL. To demonstrate, go to an MS-DOS Window (or the Start menu, Run prompt) and enter the following command line:
rundll32.exe shdocvw.dll,OpenURL c:\temp.url
This command has the same effect as double-clicking the Internet shortcut file. You can easily use Visual Basic's Shell function to call the command from code:
Shell "rundll32.exe shdocvw.dll,OpenURL c:\temp.url", vbNormalFocus
Although the API method seems like a more elegant solution, using RUNDLL32 works just as well. As a matter of fact, if you examine the InternetShortcut key in the Windows Registry (under HKEY_CLASSES_ROOT), you'll find that this is exactly how Windows launches Internet shortcuts.
An Enhanced About Box
To demonstrate how launching a Web site can work, we will create an About box with a Web site link. An About Box is a form (usually accessed through the About menu) that displays information about your program. Visual Basic includes an About box template, which is the basis for our project.
Follow these steps to create the About box example:
1. Create a new Standard EXE project in Visual Basic.
2. Click the Add Form button, or choose Project, Add Form. The Add Form dialog box appears.

 
< previous page page_745 next page >